#!/usr/bin/python2.4
# jhebert@cs.washington.edu

import time
import Queue

class Logger:
  """ This class handles chart logging.
  It uses one queue for all logs so as to
  centralize data, but allows instances
  of the class to prepend their specific name
  to the log items.
  """

  def __init__(self):
    """ Sets defaults during init which
    are normally immediately overwritten. """
    self.statusLog=Queue.Queue()
    self.name='System'

  def put(self, info):
    """ Put info onto log with this log's name
    and the current time. """
    t=[self.name, time.time()]
    toAdd=tuple(t+list(info))
    self.statusLog.put(toAdd)

  def get(self, bool):
    """ Get item off queue with bool
    if we should block. """
    return self.statusLog.get(bool)
        
  def SetChartName(self, name):
    """ This poorly named method
    creates a new logger obejct from this logger
    and sets the name as provided. """
    toReturn=Logger()
    toReturn.statusLog=self.statusLog
    toReturn.name=name
    return toReturn
